<%@ page import="pojo.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="utils.JDBCUtils" %>
<%@ page import="dao.StudentDao" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.Scanner" %>
<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021/10/19
  Time: 17:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>个人中心</title>
</head>
<body>
<%
    Cookie[] cookies1 = request.getCookies();
    String[] s1 = null;

    if (cookies1!=null){
        for (Cookie cookie : cookies1) {
            if (URLDecoder.decode(cookie.getName(), "utf-8").equals("nameinfo")){
                String str = URLDecoder.decode(cookie.getValue(),"utf-8" );
                s1 = str.split("-");
            }
        }
    }
    assert s1 != null;%>
欢迎<%=s1[0]%><hr/>
<h3 align="center">个人中心</h3>
<table width="800" border="1" align="center">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>密码</th>
        <th>性别</th>
        <th>专业</th>
        <th>年龄</th>
    </tr>
    <%
        Cookie[] cookies = request.getCookies();
        String[] s = null;
        if (cookies!=null){
            for (Cookie cookie : cookies) {
                if (URLDecoder.decode(cookie.getName(), "utf-8").equals("nameinfo")){
                    String str = URLDecoder.decode(cookie.getValue(),"utf-8" );
                    s = str.split("-");
                }
            }
        }
        String name = s[0];
        String password = s[1];
        System.out.println("name = " + name);
        System.out.println("password = " + password);
        Connection connection = JDBCUtils.getconnection();
        String sql = "select * from student where name=? and password=?";
        ResultSet rs = JDBCUtils.query(sql, name, password);
        Student student = null;
        while(rs.next()){
            //解析每一行获取的字段数据
            String id = rs.getString("id");
            String sname = rs.getString("name");
            String spassword = rs.getString("password");
            String sex = rs.getString("sex");
            String major = rs.getString("major");
            int age = rs.getInt("age");
            student = new Student(id,name,password,sex,major,age);
        }
        System.out.println(student);
        JDBCUtils.free();

    %>
    <tr>
        <td><%=student.getId() %></td>
        <td><%=student.getName() %></td>
        <td><%=student.getPassword() %></td>
        <td><%=student.getSex() %></td>
        <td><%=student.getMajor() %></td>
        <td><%=student.getAge() %></td>
    </tr>
</table>

</body>
</html>
